<?php

    class TemplateUtils
    {
        /**
         * ��������� ������ ��� ��������
         *
         * @param string $pageName
         * @param array $markers
         */
        public static function loadPageData( $pageName, $markers )
        {
            $INFO_SEPARATOR = ',';
            $isDataEmpty = !isset( $pageName ) || empty( $pageName );
            if ( $isDataEmpty )
            {
                return $markers;
            }

            $cachedJsFiles = CacheUtils::getCacheJsFiles( $pageName, Page::getJsFiles( $pageName ) );
            $cachedCssFiles = CacheUtils::getCacheCssFiles( $pageName, Page::getCssFiles( $pageName ) );
            $metaData = PageConfig::getMetaDataByPageName( $pageName );
            $cachedJsFiles = self::AddContentServerURL( $cachedJsFiles );
            $cachedCssFiles = self::AddContentServerURL( $cachedCssFiles );

            if ( $pageName == "Articles" )
            {
                $markers["articles"] = Utils::convertArticleToArray( Core::ResourceManager()->GetArticles() );
            }
            $markers["cssFiles"] = $cachedCssFiles;
            $markers["jsFiles"] = $cachedJsFiles;
            $markers["metaData"] = $metaData;

            return $markers;
        }

        private static function AddContentServerURL( $urls )
        {
            $contentServerUrl = Core::Config()->server_url->content_server_url;
            foreach( $urls as $key => $value )
            {
                $urls[$key] = ( UrlHelper::GetHost($urls[$key]) == NULL ) ? $contentServerUrl . $urls[$key] : $urls[$key];
            }
            return $urls;
        }
    }

?>